package net.lucamasini.ricette.server;

import static net.lucamasini.ricette.server.EntityManagerFactoryListener.jpaTemplateInContext;
import net.lucamasini.ricette.model.TipoIngrediente;

import org.springframework.orm.jpa.JpaTemplate;

import com.google.gwt.requestfactory.server.RequestFactoryServlet;
import com.google.gwt.requestfactory.shared.Locator;

public class TipoIngredienteLocator extends Locator<TipoIngrediente, String> {

	private final JpaTemplate template;
	
	public TipoIngredienteLocator() {
		super();

		template = jpaTemplateInContext(RequestFactoryServlet.getThreadLocalRequest().getSession(true).getServletContext());
	}

	@Override
	public TipoIngrediente create(Class<? extends TipoIngrediente> clazz) {
		return new TipoIngrediente();
	}

	@Override
	public TipoIngrediente find(Class<? extends TipoIngrediente> clazz, String id) {
		return template.find(clazz, id);
	}

	@Override
	public Class<TipoIngrediente> getDomainType() {
		return TipoIngrediente.class;
	}

	@Override
	public String getId(TipoIngrediente domainObject) {
		return domainObject.getId();
	}

	@Override
	public Class<String> getIdType() {
		return String.class;
	}

	@Override
	public Object getVersion(TipoIngrediente domainObject) {
		return domainObject.getVersion();
	}

}
